﻿using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
using QuanLyTuyenSinh.Base;
using QuanLyTuyenSinh.DataLayer;

namespace QuanLyTuyenSinh.BussinessLayer
{
    public class University
    {
        private readonly DataConfig dataConfig;
        private DataTable dtTable;

        public University()
        {
            dataConfig = new DataConfig(frmLoading.Servername, frmLoading.UserName, frmLoading.Pass);
        }

        public int Id { get; set; }
        public string UniversityDisplay { get; set; }
        public string UniversityName { get; set; }
        public string UniversityAddress { get; set; }
        public string UniversityMobile { get; set; }

        public int Insert(University obj)
        {
            int result = 0;
            string sql = string.Format("INSERT INTO  University (UniversityDisplay,UniversityName,UniversityAddress,UniversityMobile) values(N'{0}', N'{1}', N'{2}', N'{3}')"
                                       , obj.UniversityDisplay, obj.UniversityName, obj.UniversityAddress, obj.UniversityMobile);
            try
            {
                result = dataConfig.ExecuteNoneQuery(sql);
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.ToString());
            }
            return result;
        }

        public int Update(University obj)
        {
            int result = 0;
            string sql = string.Format("UPDATE University SET UniversityDisplay= N'{0}', UniversityName=N'{1}',UniversityAddress= N'{2}', UniversityMobile=N'{3}' WHERE Id=N'{4}'"
                                       , obj.UniversityDisplay, obj.UniversityName, obj.UniversityAddress, obj.UniversityMobile, obj.Id);
            try
            {
                result = dataConfig.ExecuteNoneQuery(sql);
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.ToString());
            }
            return result;
        }

        public int Delete(University obj)
        {
            int result = 0;
            string sql = string.Format("DELETE University  Where id= N'{0}'", obj.Id);
            try
            {
                result = dataConfig.ExecuteNoneQuery(sql);
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.ToString());
            }
            return result;
        }
    }
}